import server from '../server/http'

// 请求首页banner数据
const getBanners = async function() {
   var {data} = await server.get('/small4/banner/list')
   return Promise.resolve(data.data)
}

const getkj = async function(){
    var {data} = await server.get('small4/shop/goods/kanjia/list')
    return Promise.resolve(data.data)
}

const getrecommended = async function(){
    var {data} = await server.get('/small4/cms/news/list')
    return Promise.resolve(data.data)
}

const getspecial = async function(id){
    console.log(id);
    var {data} = await server.get('small4/cms/news/detail?id=' + id)
    return Promise.resolve(data.data)
}

const getTypes = async function(){
    var {data} = await server.get('small4/shop/goods/category/all')
    return Promise.resolve(data.data)
}
const getTypeList = async function(id){
    var {data} = await server.get('small4/shop/goods/list')
    var list = []
    list = data.data.filter(item=>{
        return  item.categoryId == id
    })
    return Promise.resolve(list)
}
const getDetail = async function(id){
    var {data} = await server.post('/small4/shop/goods/detail?id='+id)
    return Promise.resolve(data)
}
const getPj  = async function(id){
    var {data} = await server.post('/small4/shop/goods/reputation?goodsId='+id)
    return Promise.resolve(data)
}
const getlike = async function(){
     var {data} = await server.get('small4/shop/goods/list')
     return Promise.resolve(data.data)
}

const loginto = async function (obj){
    var {data} = await server.get('small4/user/m/login?deviceId=007&deviceName=monkey&mobile=' +obj.mobile+'&pwd='+obj.pwd )
     return Promise.resolve(data)
}

const gettopay = async function (token){
    var {data} = await server({
        method: 'post',
        url: '/small4/order/list',
        params:{
            token
        }
    })
    return Promise.resolve(data)
}

export {
    getBanners,
    getkj,
    getrecommended,
    getTypes,
    getTypeList,
    getDetail,
    getPj,
    getlike,
    getspecial,
    loginto,
    gettopay
}